<?php
abstract class GroupedFormElement extends FormElement implements DirectionalElement {
	
	protected $fieldset;
	private $elementArray = array();
	
	public function __construct($elementId, $labelText) {
		
		parent::__construct($elementId, $labelText);
		
		$this->fieldset = new FieldSet($labelText);
		$this->fieldset->setParent($this);
		$this->groupDirection = Direction::$groupVertical;
	}
	
	public function setGroupDirection($groupDirection) {
	
		$this->fieldset->setGroupDirection($groupDirection);
	}
	
	protected abstract function createElement($elementId, $text);
	
	public function addElement($elementId, $text) {
		
		$element = $this->createElement($elementId, $text);
		$this->fieldset->addElement($element);
		$this->elementArray[] = $element;
	}
	
	protected function renderElement() {
		
		foreach ($this->elementArray as $element) {
			if (strcmp($element->elementId, $this->getDefaultValue()) == 0) {
				$element->setSelected(TRUE);
			}
		}
		
		$this->fieldset->setLabelVisibility($this->labelVisibility);
		$this->fieldset->render();
	}
}
?>